On LL(k) Covering Transformation

نویسندگان

  • Gyung-Ok Lee
  • Kwang-Moo Choe
چکیده

A new transformation of a subclass of LR(k) grammars into equivalent LL(k) grammars is studied. The subclass of LR(k) grammars is called extended k-transformable. The transformed LL(k) grammars left-to-right cover the original LR(k) grammars. Previous transformations transform k-transformable and PLR(k) subclasses of LR(k) into LL(k). The new transformation is more powerful in that it handles the extended k-transformable subclass of LR(k), which strictly includes k-transformable and PLR(k) classes. 1 Introduction The LR(k) grammar suggested by Knuth is the largest class of grammars which can be deterministically parsed in bottom-up manner on reading the input strings from left to right and looking k-symbols ahead [2]. The LL(k) grammar is the counterpart of top-down parsing, but known as a subclass of LR(k) grammars. In this paper, we concentrate on the problem of transforming LR(k) grammars into LL(k) forms that leftto-right cover the original grammars. (We call such transformed grammar LL(k) covering grammar.) The k-transformable [1] and PLR(k) [4] grammars were de ned as the subclasses of LR(k) grammars, which can be transformed into LL(k) covering grammars. The k-transformable grammars were conjectured as the upper bound of such grammars [1], and the PLR(k) grammars were mentioned to be a subset of k-transformable grammars [4]. However, if we consider a grammar with rules, S ! A;A ! BXc;A ! BY d;B ! bB;B ! a;X ! BA;X ! BB; Y ! Bd, then the grammar is not k-transformable for all k 0 but PLR(1). This counterexample motivates a characterization of an extended grammar class which includes PLR(k) and k-transformable grammars and a study of an LL(k) covering transformation applicable to the class. An LL(k) covering transformation is obtained by a simulation of the actions of an LR(k) parser. The LR(k) parser changes the stack string by pushing a stack symbol on shift/reduce action and popping a top stack string on a reduce action. Accordingly, LL(k) covering grammars have to contain information about the process of the stack string becoming di erent. On the other hand, a stack string cannot be directly used as a grammar symbol because it is potentially in nite. The idea of predicting reduction goal has been introduced to express the stack string in nite representation. A reduction goal is found at a reduction time in conventional LR(k) parsing, but we can sometimes predict it in advance. This paper investigate an extension of the LL(k) covering transformations suggested in PLR(k) and k-transformable grammars. It is from a generalization of the goal prediction, which is summarized in two viewpoints: (i) the representation [A; ] in [1, 4] which can be understood as a description of a con guration of an LR(k) parser is re ned to [qA; ; qA ] by adding a parsing context of qA and qA ; (ii) when we classify the transitions of LR(k) items on the construction of LR(k) states as closure transition and goto transition, a method introduced by [1] examines only closure transitions for the prediction, but our method inspects goto transitions as well as closure ones. Those two ideas are formalized through a nondeterministic LR(k) nite automaton. A set of transition sequences in the automaton is expressed by the re ned representation men1 tioned in (i), and transition sequences including goto transitions are examined to nd predictable reduction goals. An extended LL(k) covering grammar based on the generalization is constructed in a very similar way to those of [1, 4]. The transformable grammars are de ned as extended k-transformable, which includes PLR(k) and k-transformable grammars. The organization of this paper is as follows. Section 2 contains basic de nitions. A transformation of a given grammar into an LL(k) grammar is given in section 3 after the idea for the generalized prediction is formally treated. Section 4 is devoted to proof of the LL(k) covering property of our transformation. Finally, a few non-applicable grammars are shown in section 5. 2 Basic De nitions We use notation and de nitions based on [3]. The reader is assumed to be familiar with them. The remainder of this section introduces some modi ed de nitions based on [3] that we will need subsequently. Throughout this paper, the symbolG denotes an arbitrary, but xed context-free grammarG = (N; ; P; S) (let V = N [ ): The symbol k represents an arbitrary, but xed non-negative integer. Without explicitly stated G is assumed to be LR(k). For the convenient description of LR(k) parsing, G is assumed to be augmented in the sense that P contains a special rule S0 ! S, where S0 does not occur in any other rule. Additionally, G is assumed to be reduced [3]. Lower case Greek letters, such as , , and denote vocabulary strings in V ; lower case Roman letters near the beginning of the alphabet, such as a; b; and c are terminals in , and those near the end, such as w; x; y, and z are terminal strings in ; upper case Roman letters near the end of the alphabet, such as W;X; and Y are vocabulary symbols in V . The empty string is denoted by . The reverse of a string is represented by R. For G1 = (N1; ; P1; S1) and G2 = (N2; ; P2; S2), G2 is said to be an LL(k)-cover for G1 if G2 left-toright covers [3] G1 and G2 is LL(k). A pair of [A ! : ; u] is an LR(k) item if A ! 2 P and u 2 FIRSTk( $) where the symbol $ not in is the end marker of an input string. If [A ! : ; u] is an LR(k) item, then FIRSTk([A ! : ; u]) means the set fx 2 FIRSTk( u)g; if q is a set of LR(k) items, then FIRSTk(q) means the set S[A! : ;u]2q FIRSTk([A! : ; u]). Let IG k be the set of LR(k) items over G. A nondeterministic LR(k) nite automaton is ~ MG k = (IG k ; V;! ; [S0 ! :S; $]; ;) with the set of states IG k , the set of transition symbols V , the initial state [S0 ! :S; $], the set of nal states ;, and a transition function ! which is de ned from IG k (V [f g) to 2IG k : (i) goto transition: [A ! :X ; u] !X [A ! X: ; u] for some X 2 V ; (ii) closure transition: [A ! :B ; u] ! [B ! : ; v] where v 2 FIRSTk( u). If I0 !X1 I1 !X2 !Xn In(n 0) holds, then we write I0 ! X1X2 Xn In. 2 An LR(k) item [A ! :X ; u] is called a shift item if X 2 , a reduce item if X = , and a terminal item if the item is a shift or reduce item. A function T is de ned to take terminal items derived from a given item: T ([A! : ; u])= f[B ! : ; v]j[A! : ; u] ! [B ! : ; v]; [B ! : ; v] is a terminal itemg. If q is a set of LR(k) items, then T (q) = f[B ! : ; v]j [B ! : ; v] 2 T ([A ! : ; u]), [A ! : ; u] 2 qg. Note that there is no transition for the terminal items. A sequence of transitions in ~ MG k , = I0 !X1 I1 !X2 I2 !X3 !Xn In is called a path. If In is a terminal item, then is called a terminal-path. A sequence of closure transitions in a path such that the immediate predecessor and the immediate successor, if exist are not closure transition is called a segment. A function from IG k (V [ f g) to 2IG k is de ned from the ! function: if [A ! : ; u] 2 IG k and X 2 (V [f g), then ([A! : ; u]; X) = f[B ! : ; v]j [A! : ; u]! X [B ! : ; v]g. If q is a set of LR(k) items, then we extend to (q;X) = SI2q (I;X) and (q;X1X2 Xn) = (( ( (q;X1); X2); ); Xn) for some Xi 2 V; i = 1; ; n. The ~ MG k is converted to a deterministic automaton MG k = (Q; V; LR; qS 0 ; ;) where Q is the set of LR(k) states, which is the smallest set of fqS 0 g[ f LR(q;X)j q 2 Q;X 2 V g; LR is the restriction of to Q V . qS 0 is the initial state de ned by ([S0 ! :S; $]); the set of nal states is ;. We abbreviate LR(qS 0 ; ) by VALIDk( ) and [ ]k in [3]. An LR(k) parser is derived from the MG k . A con guration (LR(k) parsing con guration) of the parser is of the form [ ]k [ ]k x$ where [ ]k [ ]k is a stack string, and x is the remaining input string. The last symbol [ ]k of the stack string is the current state. The initial con guration for input string x is [ ]k x$, and the accepting con guration is [ ]k[S]k $. A con guration [ ]k [ ]k y$ such that [ ]k x$ ) [ ]k [ ]k y$ ) [ ]k[S]k $ is a valid LR(k) parsing con guration. A sequence of moves from the initial con guration to the accepting con guration is a valid LR(k) parsing sequence. Any subsequence of a valid LR(k) parsing sequence is a valid LR(k) parsing subsequence. The LR(k) parser has shift and reduce actions, and the moves for the actions are as follows. (i) shift action: [ ]k [ ]k ay$ ) [ ]k [ ]k [ a]k y$ if [A ! :a ; u] 2 VALIDk( ) and maxf0; k 1g:y$ 2 FIRSTmaxf0;k 1g( u); (ii) reduce action: [ ]k [ ]k [ ]k x$ ) [ ]k [ ]k[ A]k x$ if [A ! :; u] 2 VALIDk( ) where A 6= S0 and u = k:x$. Note that the shift action at [ ]k [ ]k ay$ and the reduce action at [ ]k [ ]k [ ]k x$ are determined by the terminal items [A! :a ; u] and [A! :; u], respectively. If an LR(k) state has two di erent terminal items [A ! : ; u]; [B ! :; v] where v 2 FIRSTk( u), then there exists an LR(k) con ict at the state. A output function is a mapping from the set of the moves of the parser to P [ f g: ([ ]k ay$) [ ]k[ a]k y$) = ; ([ ]k [ ]k x$) [ ]k[ A]k x$) = A! . 3 The following three properties are fundamental to the arguments in the remaining sections. Property 2.1 There exists a sequence of transitions in ~ MG k such that [A ! :!; u] ! [B ! : ; v], and [A ! :!; u] 2 VALIDk( ) for some viable pre x i there exists a derivation S ) rm Aw )rm !w ) rm Bzw )rm zw ) rm yzw in G where = , k:w$ = u, and k:zw$ = v. 2 Property 2.2 There exist rule strings, r1; 1; r2; 2 inG such that S ) rm Aw )r1 rm !w ) 1 rm Bzw )r2 rm zw ) 2 rm yzw i there exist valid LR(k) parsing subsequences 2; r2; 1; r1 such that [ ]k [ ]k [ ]k yzw$ ) 2 [ ]k [ ]k [ ]k zw$ )r2 [ ]k [ ]k[ B]k zw$ ) 1 [ ]k [ !]k w$ )r1 [ ]k[ A]k w$ where ( 2) = R2 , (r2) = r2, ( 1) = R1 , and (r1) = r1. 2 We conclude from Property 2.1 and Property 2.2 that the following property holds. Property 2.3 There exists a sequence of transitions in ~ MG k such that [A ! :!; u] ! [B ! : ; v], and [A ! :!; u] 2 VALIDk( ) for some viable pre x i there exists a valid LR(k) parsing subsequence such that [ ]k [ ]k [ ]k yzw$ ) [ ]k [ ]k [ ]k zw$ ) [ ]k [ ]k [ B]k zw$ ) [ ]k [ !]k w$ ) [ ]k[ A]k w$ where = , k:w$ = u, and k:zw$ = v. 2 3 Generation of LL(k) grammars This section suggests an LL(k) transformation applicable to a new class, called extended k-transformable grammar. We rst give a representation for a set of paths in ~ MG k which is used to describe a valid LR(k) parsing con guration. Then we de ne relations which nd predictable reduction goals by examining the paths in a path set representation. A path set representation corresponds to a nonterminal symbol in our transformation, and the change of a con guration according to each action in the LR(k) parser is expressed as a grammar rule of the proposed transformation. 3.1 Representation of Path Sets For A 2 N , let qA be a subset of an LR(k) state such that each item in qA is of the form [A ! :!; u] for some !; u. Let 2 V and qA be a set of LR(k) items with qA T ( (qA; )). A triple hqA; ; qA i represents f j is a terminal path of the form 0 !X1 1 !X2 !Xn n, i = Ii;0 ! Ii;1 ! ! Ii;mi for each i = 0; 1; ; n, I0;0 2 qA, In;mn 2 qA g where = X1X2 Xn; Xi 2 V; i = 1; ; n. Note that each i, 0 i n is a segment. The i is referred to as segmenti of . If = , then SEGj jhqA; ; qA i = fI0; I1; ; ImjI0 ! I1 ! ! Im is segmentj j of a path in hqA; ; qA ig. Specially, SEGj jhqA; ; qA i is represented by LSEGhqA; ; qA i. A path in hqA; ; qA i is shown in Figure 1. 4 X1 X2 Xn I1;1 I1;m1 I1;0 In;0 In;1 I2;0 In 1;0 In 1;1 I0;1 I0;m0 In 1;mn 1 segment1 segmentn 1 segmentn segment0 I0;0 2 qA In;mn 2 qA Figure 1: A path in hqA; ; qA i where = X1X2 Xn We introduce a terminology for an intuitive explanation of this work. It is said that a valid LR(k) parsing con guration [ ]k [ ]k [ ]k x$ is described by hqA; ; qA i when the next action of the con guration is determined by [B ! : ; v] for some [B ! : ; v] 2 qA , and there exists a valid LR(k) parsing subsequence [ ]k [ ]k [ ]k yz$ ) [ ]k [ ]k [ !]k z$ ) [ ]k [ ]k[ A]k z$ where yz = x and k:z$ = u for some [A! :!; u] 2 qA. It would be noted that a valid LR(k) parsing con guration [ ]k [ ]k x$ is described by a path set hqS0 ; ; qS0 i where qS0 = f[S0 ! :S; $]g and qS0 = T ( (qS0 ; )). On the other hand, such path set representation is potentially in nite because it is based on the stack string. We would like to have a nite collection of path sets such that all valid LR(k) parsing con gurations can be described by the path sets in the collection. The next section gives a solution of the problem on the in niteness of path set representation by suggesting reduction goal prediction. 3.2 Prediction of Reduction Goals A speci c segment of each path in a given path set is examined to nd predictable reduction goal. De nition 1 (~ relation) Let qA; ; qA be same as before, B 2 N , and = . Then (hqA; ; qA i, B; ) 2 ~ if for each segmentj j of a path in hqA; ; qA i, there exists i(0 i m) such that Ii = [B ! : ; v] for some ; v where = I0 ! ! Ii ! ! Im. 2 In order to nd the nonterminal B satisfying the condition of ~ , it is enough to visit the cycle at most one time in each segment. We reform ~ relation to ̂ relation in terms of path set representation. The ̂ relation includes the general case that some paths in hqA; ; qA i do not contain the item [B ! : ; v] on the segmentj j. 5 De nition 2 (̂ relation) Let (hqA; ; qA i, B; ) 2 ~ , = , and qA ; qB be sets of LR(k) items with qA qA and qB = qA . Then hqA; ; qA i ̂ (hqB ; ; qB i, hqA; B; qA Bi) satisfying for each segmentj j = I0 ! I1 ! ! Im of a path in hqA; ; qA i, there exists i; 0 i m such that Ii = [B ! : ; v], qB = S fIig, and qA B = T ( qA B) where qA B = S f[C ! B: ; w]jIi 1 = [C ! :B ; w]g: (Here, ranges over all paths in hqA; ; qA i.) 2 Figure 2 shows a snapshot in De nition 2 with Il;0 = I0; ; Il;i = Ii; ; Il;ml = Im. Il;0 I0;1 In;0 In;1 Il;i 1 = [C ! :B ; w] Il;i(= [B ! : ; v]) 2 qB In;mn 2 qA I0;m0 Il;ml [C ! B: ; w] B I0;0 2 qA Figure 2: j j = l Example 1 Let G1 = (fS;Ag; fa; d; b; cg, fS ! aAd;A! ab;A! aA;A! bcg; S): Note that G1 is LR(1). Here, two selected ̂ relations are shown: * [S0 ! :S; $] ; aa; 8><>>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>=>>; +0;1;2̂0BB@ [A! :ab; d] [A! :aA; d] ; ; [A! :ab; d] [A! :aA; d] 3; [S0 ! :S; $] ; aaA; [A! aA:; d] 1CCA ;(1) * [A! :ab; d] [A! :aA; d] ; a; 8>><>>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>>=>>; +4;5̂0BBBB@ [A! :ab; d] [A! :aA; d] ; ; [A! :ab; d] [A! :aA; d] 4; [A! :ab; d] [A! :aA; d] ; aA; [A! aA:; d] 1CCCCA: (2) The subscript si; i = 0; 1; ;m in hq A; ; q A is0;s1; ;sm means that state si in Figure 3 consists of the items in SEGihq A; ; q A i. In Figure 3, a solid line connects from SEGi to SEGi+1 with label Xi+1, i = 1; ; j j where = X1 Xj j; a dashed line connects from LSEGhq A; ; q A i to LSEGhq B ; ; q B i where hq A; ; q Aî(hq B ; ; q B i; hq A; B; q A B). A string x on the dashed line means that if a valid LR(1) parsing con guration described by hq A; ; q A i has x as lookahead, then the con guration is described by hq B ; ; q B i. 2 6 0:[S’->.S,$] [S->.aAd,$] 1:[S->a.Ad,$] [A->.ab,d] [A->.aA,d] a 2:[A->a.b,d] [A->a.A,d] [A->.ab,d] [A->.aA,d] [A->.bc,d] a 3:[A->.ab,d] [A->.aA,d] a 4:[A->.ab,d] [A->.aA,d] 5:[A->a.b,d] [A->a.A,d] [A->.ab,d] [A->.aA,d] [A->.bc,d] a a Figure 3: SEGs over ̂ relations (1) and (2) By de nition of ̂, we can easily observe the following property. Property 3.1 Let = . Assume that [ ]k [ ]k [ ]k yz$ is described by hqA; ; qA i, and there exists a valid LR(k) parsing subsequence such that [ ]k [ ]k [ ]k yz$) [ ]k [ ]k [ !]k z$) [ ]k [ ]k [ A]k z$ (3) where k:z$ = u for some [A! :!; u] 2 qA. If hqA; ; qA î(hqB ; ; qB i; hqA; B; qA Bi), and the next action at [ ]k [ ]k [ ]k yz$ is determined by an item in qB , then there exists a con guration [ ]k [ ]k[ B]k y2z$ such that the subsequence (3) is of the form [ ]k [ ]k [ ]k y1y2z$) [ ]k [ ]k [ ]k y2z$ ) [ ]k [ ]k[ B]k y2z$) [ ]k [ ] [ !]k z$) [ ]k [ ][ A]k z$ where y1y2 = y and k:y2z$ = v for some [B ! : ; v] 2 qB . 2 In Property 3.1, it would be worth pointing out that [ ]k [ ]k [ ]k yz$ is described by hqB ; ; qB i as well as hqA; ; qA i. In this way, a valid LR(k) parsing con guration can be described by a bounded length of path set than a potentially in nite path set if some appropriate ̂ relation exists. Additionally, observe that [ ]k [ ]k [ B]k y2z$ is described by hqA; B; qA Bi. This fact is helpful to understand a prediction rule in the proposed transformation. 3.3 Cyclic Path Set The ~ relation is potentially in nite, but it can be e ectively computed on the basis of Property 3.2. A cyclic path set is introduced to discuss the e ectiveness. 7 A loop is a sequence of states qi; qi+1; ; qj(j > i) such that qi = qj and no other pair of states is identical. A sequence q0; q1; ; qn contains the loop p0; p1; ; pm if there is an i such that qi+j = pj , for each j; 0 j m. The sequence contains r occurrences of the loop if there are r di erent values for such an i. A sequence of states is called simple if it contains no more than two occurrences of same loop. A path set hqA; ; qA i is said to be cyclic if the sequence SEG0hqA; ; qA i, SEG1hqA; ; qA i, , SEGj jhqA; ; qA i is not simple. Property 3.2 Assume that the sequence SEG0hqA; ; qA i, SEG1hqA; ; qA i, ; SEGj j hqA; ; qA i contains r(r 3) occurrences of a loop p0; p1; ; pm(m 1). If (hqA; ; qA i; B; ) 2 ~ for some B and , then there exist and such that (hqA; ; qA i, B; ) 2 ~ where qA = qA and the sequence SEG0hqA; ; qA i, SEG1hqA; ; qA i, , SEGj jhqA; ; qA i does not contain more than two occurrences of the loop p0; p1; ; pm. 2 We can nd the strings and by analysis of a transition graph whose set of nodes consists of SEGihqA; ; qA i; i = 0; 1; ; j j and whose edges are all pairs (SEGihqA; ; qA i; SEGi+1hqA; ; qA i), i = 0; ; j j 1. Each edge (SEGihqA; ; qA i; SEGi+1hqA; ; qA i) is labeled by all those Xi+1, i = 0; ; j j 1 where = X1 Xj j. Example 2 is presented as an example of Property 3.2. Example 2 For G1, consider a cyclic path set: * [S0 ! :S; $] ; aaa3aa; 8>><>>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>>=>>; +0;1;2;2;2;2;3;4 : (Here the subscript means the state of Figure 4.) The sequence of SEGs 0,1,2,2,2,2,3,4 contains three occurrences of a loop 2,2, and * [S0 ! :S; $] ; aaa3aa; 8>><>>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>>=>>; + ̂0BB@ [A! :ab; d] [A! :aA; d] ; ; [A! :ab; d] [A! :aA; d] 5; [S0 ! :S; $] ; aaa3aaA; [A! aA:; d] 1CCA(4) holds. On the other hand, a sequence 0,1,2,2,2,3,4 is obtained by removing one instance of the loop 2,2 in the sequence 0,1,2,2,2,2,3,4. Observe that the relation * [S0 ! :S; $] ; aaa2aa; 8>><>>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>>=>>; +0;1;2;2;2;3;4̂0BB@ [A! :ab; d] [A! :aA; d] ; ; [A! :ab; d] [A! :aA; d] 5; [S0 ! :S; $] ; aaa2aaA; [A! aA:; d] 1CCA (5) holds. In fact, the left side path set of the relation (5) is non-cyclic. 2 8 0:[S’->.S,$] [S->.aAd,$] 1:[S->a.Ad,$] [A->.aA,d] a 2:[A->a.A,d] [A->.aA,d] a a 3:[A->a.A,d] [A->.ab,d] [A->.aA,d] a 4:[A->a.b,d] [A->a.A,d] [A->.ab,d] [A->.aA,d] [A->.bc,d] a 5:[A->.ab,d] [A->.aA,d] a Figure 4: SEGs over ̂ relations (4) and (5) Property 3.2 means that for the and , if (hqA; ; qA i; B; ) 2 ~ does not hold, then (hqA; ; qA i, B; ) 2 ~ does not hold. By repeated application of this process, a useful property is obtained that whether (hqA; ; qA i, B; ) 2 ~ or not where hqA; ; qA i is cyclic depends on whether (hqA; ; qA i; B; ) 2 ~ or not where hqA; ; qA i is non-cyclic. As a result, we know that it is not necessary to test the condition of ~ with cyclic path sets, and so ~ can be e ectively computed. Analogously, we can show that the ̂ relation can be e ectively computed. 3.4 Transformation A restricted subrelation LL of ̂ is de ned in order to preserve LL-ness of the suggested transformation. De nition 3 ( LL relation) LL is a subrelation of ̂ satisfying Condition 1, Condition 2(a), and Condition 2(b). Condition 1: For two distinct relations, hqA; ; qA i LL (hqB ; ; qB i, hqA; B; qA Bi); hqA; ; qA i LL (hqC ; ; qC i, hqA; C; qA Ci), FIRSTk(qB ) \ FIRSTk(qC ) = ;. Condition 2: For each hqA; ; qA i LL (hqB ; ; qB i; hqA; B; qA Bi), (a) FIRSTk(qB ) \ FIRSTk(qA qB ) = ;. (b) FIRSTk(qA B) \ FIRSTk(qB B ) = ;, if we let qB B = T ( (qB ; B)). 2 We now give an algorithm for deciding whether or not a grammar is extended k-transformable. A symbol [qA; ; qA ] is said to be cyclic nonterminal if hqA; ; qA i is cyclic. Algorithm 1 (extended k-transformable grammar) Let G be LR(k) grammar. If there exists LL such that T (G; ) through Algorithm 2 has no cyclic nonterminal, then G is extended k0-transformable where k0 = 1 if k = 0 and otherwise, k0 = k. 2 For given G and relation, the following algorithm gives a transformed grammar T (G; ) or an error indicator saying that a cyclic nonterminal is found during T (G; ) is constructed. 9 Algorithm 2 (Generation of T (G; )) Input: G and relation Output: T (G; ) or an error message indicating that a cyclic nonterminal is found in T (G; ). Method: T (G; ) is (N; [ f g; P ; S) where S = [qS0 ; ; T (qS0)] with qS0 = f[S0 ! :S; $]g, N is the set of nonterminals appeared in P , and P is the set of rules obtained by the following steps. 1. N = fSg. 2. P = ;. 3. repeat until (N does not change or a cyclic nonterminal is found in N) Let [qA; ; qA ] 2 N. (a) If = A, then suspension type1: P = P [ f[qA; A; qA A ]! g where qA A = T ( (qA; A)). (b) For each item I 2 qA , do the following: i. If I 2 qB where hqA; ; qA i (hqB ; ; qB i; hqA; B; qA Bi), then prediction type: P = P [ f[qA; ; qA ]! [qB ; ; qB ][qA; B; qA B ]g. ii. Otherwise, if I is a shift item and is of the form [B ! :a ; v], then read type: P = P [f[qA; ; qA ]! a[qA; a; qA a]gwhere qA a = T (f[B0 ! 0a: 0; v0]j[B0 ! 0:a 0; v0] 2 qA g) iii. Otherwise, if I is a reduce item and is of the form [B ! :; v], then reduction type: P = P [ f[qA; ; qA ] ! [qA; B; qA B ]g where = and qA B = T (f[C ! B: ; w]j ([A! :!; u]! [C ! :B ; w]! [B ! :; v0]) 2 hqA; ; qA i g). (c) New nonterminals appeared in new rules are added to N. 4. If there is no cyclic nonterminal in T (G; ), then return (T (G; )); otherwise, return (a cyclic nonterminal is found). 2 Hereafter, we assume that G is extended k-transformable, is the relation that makes T (G; ) to have no cyclic nonterminals, and T (G; ) is the transformed grammar according to Algorithm 2. The left side of a rule symbolizes a path set describing the current con guration of the LR(k) parser. Read or reduction rules simulate shift or reduce actions of the LR(k) parser, respectively. The right side of the rule represents a path set describing the reached con guration after the corresponding action is performed. 1We follow the terminology "suspension" used in [1]. 10 On the other hand, a prediction rule gives another path set describing the current con guration, and a suspension rule denotes a reduction into a goal previously predicted. We de ne a function T from P to P [ f g as T (r) = B ! , if r = [qA; ; qA ] ! [qA; B; qA B ] and otherwise, T (r) = . Example 3 For G1, de ne relation as ̂ relations (1) and (2) in Example 1. Then the transformed grammar T (G1; ) has no cyclic nonterminal, and hence G is extended 1-transformable. On the other hand, G1 is not 1-transformable according to [1]. Appendix A discusses a comparison between our work and the work [1] from the viewpoint of the two ideas for the generalized prediction. (A) The rules of T (G1; ) are shown in the following, and observe that T (G1; ) is an LL(1) grammar. [S0 ! :S; $] ; ; [S ! :aAd; $] ! a" [S0 ! :S; $] ; a; ( [A! :ab; d] [A! :aA; d] [A! :bc; d] ) # " [S0 ! :S; $] ; a; ( [A! :ab; d] [A! :aA; d] [A! :bc; d] ) # ! b [S0 ! :S; $] ; ab; [A! b:c; d] " [S0 ! :S; $] ; a; ( [A! :ab; d] [A! :aA; d] [A! :bc; d] ) # ! a264 [S0 ! :S; $] ; aa; 8><>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>=>; 375 [S0 ! :S; $] ; ab; [A! b:c; d] ! c [S0 ! :S; $] ; abc; [A! bc:; d] 264 [S0 ! :S; $] ; aa; 8><>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>=>; 375 ! [A! :ab; d] [A! :aA; d] ; ; [A! :ab; d] [A! :aA; d] [S0 ! :S; $] ; aaA; [A! aA:; d] 264 [S0 ! :S; $] ; aa; 8><>: [A! a:b; d] [A! :ab; d] [A! :aA; d] [A! :bc; d] 9>=>; 375 ! b [S0 ! :S; $] ; aab; [A! ab:; d] [A! b:c; d] [S0 ! :S; $] ; abc; [A! bc:; d] ! [S0 ! :S; $] ; aA; [S ! aA:d; $] [S0 ! :S; $] ; aA; [S ! aA:d; $] ! d [S0 ! :S; $] ; aAd; [S ! aAd:; $]

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

On covering designs with block size 5 and index 11≤λ≤21: the case v≡0(mod 4)

Let V be a finite set of order v. A (v,k,A.) covering design of index A. and block size k is a collection of k-element subsets, called blocks, such that every 2-subset of V occurs in at least '}.. blocks. The covering problem is to determine the minimum number of blocks, a (v, k, A.), in a covering design. It is well known that a(v,k''}..)Lr~~=~'}..ll=(v,k,A.), where rxl is the smallest integer

متن کامل

Molecular mechanisms of continuous light inhibition of Atlantic salmon parr–smolt transformation

Atlantic salmon (Salmo salar) rely on changes in photoperiod for the synchronization of the developmental events constituting the parr–smolt transformation. In the absence of photoperiod cues, parr–smolt transformation is incomplete, and such ‘pseudo-smolts’ normally fail to adapt to seawater. The present study addresses the endocrine and molecular mechanisms controlling the development of hypo...

متن کامل

A general scheme for some deterministically parsable grammars and their strong equivalents

In the past years there have been many attempts to fill in the gap between the classes of LL(k) and LR(k) grammars with new classes of deterministically parsable grammars. Almost always the introduction of a new class was accompanied by a parsing method and/or a grammatical transformation fitting the following scheme. If parsers were at the centre of the investigation the new method used to be ...

متن کامل

Statistical Genetic Studies on Cattle Breeding for Dairy Productivity in Bangladesh: I. Genetic Improvement for Milk Performance of Local Cattle Populations

Genetic parameters for dairy performance traits were estimated, breeding values for the traits of all breeding sires and cows were predicted and the genetic trends were estimated using the breeding values in the Central Cattle Breeding Station (CCBS). A total of 3,801 records for Bangladeshi Local, 756 records for Red Sindhi and 959 records for Sahiwal covering the period from 1961 to 1997 were...

متن کامل

L-functions of regular coverings of graphs

Let π1 : K H , π2 : H G and π2π1 : K G be three finite regular coverings of graphs, and let σ be a representation of the covering transformation group of π1. We show that the L-function of G associated to the representation of the covering transformation group of π2π1 induced from σ is equal to that of H associated to σ by means of ordinary voltage assignments. © 2003 Elsevier Science Ltd. All ...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2007